package 集合;

import java.util.ArrayList;
import java.util.List;

public class ListUse {
	public static void main(String[] args) {
		List<Integer> integers = createList();
		System.out.println(hasValue(integers, 1)); //true
		System.out.println(hasValue(integers, new int[]{1})); //false
		System.out.println(removeOne(integers, 1)); // 删除成功：true
		System.out.println(removeOne(integers, 0)); // 删除失败：false
		int index = getIndex(integers, 3); //找到3元素对应的下标，这里我们删除了第一个元素，所以应该是[1]
		System.out.println(index);
		List<Integer> subList = integers.subList(1, 3); //不能超过最大值
		System.out.println(subList);
		retainALl();
	}
	static void retainALl(){
		List<Integer> list = createList();
		ArrayList<Integer> integers = new ArrayList<Integer>();
		integers.add(1);
		boolean b = list.retainAll(integers);
		System.out.println(b);
	}
	// 复制
	static List<Integer> copyList(List<Integer> integers) {
		return new ArrayList<>(integers);
	}

	static int getIndex(List<Integer> integers, Object target) {
		return integers.indexOf(target);
	}

	static boolean removeOne(List<Integer> integers, Object removeTarget) {
		return integers.remove(removeTarget);
	}

	static List<Integer> createList() {
		ArrayList<Integer> integers = new ArrayList<Integer>();
		for (int i = 0; i < 10; i++) {
			integers.add(i + 1);
		}
		return integers;
	}

	static boolean hasValue(List<Integer> integers, Object value) {
		return integers.contains(value);
	}
}
